﻿#include "CVideoState.h"

CVideoState::CVideoState(CDevDataCam* pDevData, QWidget *parent)
	: m_pDevData(pDevData),QWidget(parent)
{
	ui.setupUi(this);
	m_sNormalLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(120, 120, 120);";
	m_sWorkLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(0, 255, 0);";
	m_sAlarmLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(255, 0, 0);";
	m_sWarningLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(255,255,0);";
	m_pTimer = new QTimer(this);
	ui.labelCamerName->setText(m_pDevData->m_sCamerName);
	initUI();
	connect(m_pTimer, SIGNAL(timeout()), this, SLOT(slotRefreshUI()));
}

CVideoState::~CVideoState()
{
	m_pTimer->stop();
	delete m_pTimer;
	m_pTimer = nullptr;
}

void CVideoState::initUI()
{
	ui.labelBeltForeign->hide();
	ui.labelBeltForeign2->hide();
	ui.labelBeltDeviation->hide();
	ui.labelBeltDeviation2->hide();
	ui.labelSmokeMakeCall->hide();
	ui.labelSmokeMakeCall2->hide();
	ui.labelBeltDeviation->hide();
	ui.labelBeltDeviation2->hide();
	ui.labelTemp->hide();
	ui.labelTemp2->hide();
	ui.labelBlock->hide();
	ui.labelBlock2->hide();
	ui.labelStreet->hide();
	ui.labelStreet2->hide();
	ui.labelCoalFlow->hide();
	ui.labelCoalFlow2->hide();
	ui.labelLargeCoal->hide();
	ui.labelLargeCoal2->hide();
	ui.labelSafetyHelmet->hide();
	ui.labelSafetyHelmet2->hide();
	ui.labelSmokeFire->hide();
	ui.labelSmokeFire2->hide();
	ui.labelPerimeterProtrct->hide();
	ui.labelPerimeterProtrct2->hide();
	ui.labelThrow->hide();
	ui.labelThrow2->hide();
	if (m_pDevData == nullptr)
		return;
	m_pDevData->m_pMutex->lock();
	QVector<int> vecAlg = m_pDevData->m_vecAlgType;
	m_pDevData->m_pMutex->unlock();
	for (int i = 0; i < vecAlg.size(); i++)
	{
		int nAlgType = vecAlg[i];
		switch (nAlgType)
		{
		case enBeltDeviation:
			ui.labelBeltDeviation->show();
			ui.labelBeltDeviation2->show();
			break;
		case enBeltForeign:
			ui.labelBeltForeign->show();
			ui.labelBeltForeign2->show();
			break;
		case enSmokeMakeCall:
			ui.labelSmokeMakeCall->show();
			ui.labelSmokeMakeCall2->show();
			break;
		case enTemp:
			ui.labelTemp->show();
			ui.labelTemp2->show();
			break;
		case enBlock:
			ui.labelBlock->show();
			ui.labelBlock2->show();
			break;
		case enStreet:
			ui.labelStreet->show();
			ui.labelStreet2->show();
			break;
		case enCoalFlow:
			ui.labelCoalFlow->show();
			ui.labelCoalFlow2->show();
			break;
		case enLargeCoal:
			ui.labelLargeCoal->show();
			ui.labelLargeCoal2->show();
			break;
		case enSafetyHelmet:
			ui.labelSafetyHelmet->show();
			ui.labelSafetyHelmet2->show();
			break;
		case enSmokeFire:
			ui.labelSmokeFire->show();
			ui.labelSmokeFire2->show();
			break;
		case enPerimeter:
			ui.labelPerimeterProtrct->show();
			ui.labelPerimeterProtrct2->show();
			break;
		case enThrow:
			ui.labelThrow->show();
			ui.labelThrow2->show();
			break;
		default:
			break;
		}
	}
}

void CVideoState::refreshData(bool bRefresh)
{
	if (bRefresh)
	{
		m_pTimer->start(1000);
	}
	else
	{
		m_pTimer->stop();
	}
}

void CVideoState::slotRefreshUI()
{
	if (!isVisible())
	{
		return;
	}
	m_pDevData->m_pMutex->lock();
	//摄像头状态
	if (m_pDevData->m_bLogin)
	{
		ui.labelVideoState->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelVideoState->setStyleSheet(m_sAlarmLamp);
	}

	//堆煤煤流占比
	if (m_pDevData->m_bCoalFlow)
	{
		ui.labelCoalFlow->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelCoalFlow->setStyleSheet(m_sAlarmLamp);
	}

	//皮带异物
	if (m_pDevData->m_bBeltForeign)
	{
		ui.labelBeltForeign->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelBeltForeign->setStyleSheet(m_sAlarmLamp);
	}

	//大块煤检测
	if (m_pDevData->m_bLargeCoal)
	{
		ui.labelLargeCoal->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelLargeCoal->setStyleSheet(m_sAlarmLamp);
	}

	//皮带跑偏算法
	if (m_pDevData->m_bBeltDeviation)
	{
		ui.labelBeltDeviation->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelBeltDeviation->setStyleSheet(m_sAlarmLamp);
	}

	//安全帽反光衣
	if (m_pDevData->m_bSafetyHelmet)
	{
		ui.labelSafetyHelmet->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelSafetyHelmet->setStyleSheet(m_sAlarmLamp);
	}

	//烟雾火点
	if (m_pDevData->m_bSmokeFire)
	{
		ui.labelSmokeFire->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelSmokeFire->setStyleSheet(m_sAlarmLamp);
	}

	//抽烟打电话
	if (m_pDevData->m_bSmokeMakeCall)
	{
		ui.labelSmokeMakeCall->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelSmokeMakeCall->setStyleSheet(m_sAlarmLamp);
	}

	//测温报警
	if (m_pDevData->m_bTemp)
	{
		ui.labelTemp->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelTemp->setStyleSheet(m_sAlarmLamp);
	}

	//周界防范
	if (m_pDevData->m_bPerimeter)
	{
		ui.labelPerimeterProtrct->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelPerimeterProtrct->setStyleSheet(m_sAlarmLamp);
	}

	//传输带堵料
	if (m_pDevData->m_bBlock)
	{
		ui.labelBlock->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelBlock->setStyleSheet(m_sAlarmLamp);
	}

	//抛洒滴漏
	if (m_pDevData->m_bThrow)
	{
		ui.labelThrow->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelThrow->setStyleSheet(m_sAlarmLamp);
	}

	//街面行为
	if (m_pDevData->m_bStreet)
	{
		ui.labelStreet->setStyleSheet(m_sWorkLamp);
	}
	else
	{
		ui.labelStreet->setStyleSheet(m_sAlarmLamp);
	}
	m_pDevData->m_pMutex->unlock();
}
